<template>
  <div class="notificationManagementList">
    <el-card>
      <div class="noticeListBox">
        <el-input placeholder="请输入ID" v-model="id" style="width: 200px">
          <template slot="prepend">ID</template>
        </el-input>
        <el-input
          placeholder="请输入内容"
          v-model="content"
          style="margin-left: 20px; width: 200px"
        >
          <template slot="prepend">内容</template>
        </el-input>

        <el-date-picker
          v-model="messageTimeVal"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="callStatisticsPickerOptions"
          value-format="yyyy-MM-dd"
          @change="focusA"
        >
        </el-date-picker>

        <el-button class="btn" @click="noticeListBtn" style="margin-left: 20px"
          >查找搜索</el-button
        >
        <el-button @click="addPush" class="btn" style="margin-left: 20px"
          >新增推送</el-button
        >
      </div>
      <div class="p">
        <p :class="{ active: index == 0 }" @click="activeStatusA()">未发送</p>
        <p :class="{ active: index == 1 }" @click="activeStatusB()">已发送</p>
      </div>
      <!-- 未发送 -->
      <div v-if="this.index == 0">
        <el-table :data="tableData" v-loading="loading" style="width: 100%">
          <el-table-column prop="id" label="ID"> </el-table-column>
          <el-table-column prop="title" label="标题"> </el-table-column>
          <el-table-column prop="content" label="内容"> </el-table-column>
          <el-table-column prop="img" label="图片">
            <template slot-scope="scope">
              <img
                :src="scope.row.img"
                alt=""
                class="img"
                preview
                v-if="scope.row.img !== ''"
              />
              <img
                src="https://ui-avatars.com/api/?name=无图片&length=3&font-size=0.28"
                alt
                v-else
                class="img"
              />
            </template>
          </el-table-column>
          <el-table-column prop="url" label="链接"> </el-table-column>
          <el-table-column prop="creationTime" label="投送时间">
          </el-table-column>
          <el-table-column prop="launch" label="投送用户">
            <template slot-scope="scope">
              <p v-for="i in scope.row.launch" :key="i">
                <span>{{
                  i == 1
                    ? "男用户"
                    : i == 2
                    ? "女用户"
                    : i == 0
                    ? "投放指定用户"
                    : "VIP用户"
                }}</span>
              </p>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="publisher" label="发布者"> </el-table-column> -->
          <el-table-column label="操作" width="300px">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="withdrawBtn(scope.row)"
                type="danger"
                v-if="scope.row.state == 0"
                >撤回</el-button
              >
              <!-- <span v-if="scope.row.state == 1">已撤回</span> -->
              <!-- <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              v-if="scope.row.state == 0"
              >已撤回</el-button
            > -->
              <el-button size="mini" @click="editBtn(scope.row)" type="primary"
                >编辑</el-button
              >
              <el-button
                size="mini"
                @click="sendNowBtn(scope.row)"
                type="success"
                >立即发送</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="page"
          :limit.sync="pageSize"
          @pagination="getList"
        />
      </div>
      <!-- 已发送 -->
      <div v-if="this.index == 1">
        <el-table :data="tableDataA" v-loading="loadingA" style="width: 100%">
          <el-table-column prop="id" label="ID"> </el-table-column>
          <el-table-column prop="title" label="标题"> </el-table-column>
          <el-table-column prop="content" label="内容"> </el-table-column>
          <el-table-column prop="img" label="图片">
            <template slot-scope="scope">
              <img
                :src="scope.row.img"
                preview
                alt=""
                class="img"
                v-if="scope.row.img !== ''"
              />
              <img
                src="https://ui-avatars.com/api/?name=无图片&length=3&font-size=0.28"
                alt
                v-else
                class="img"
              />
            </template>
          </el-table-column>
          <el-table-column prop="url" label="链接"> </el-table-column>
          <el-table-column prop="creationTime" label="投送时间">
          </el-table-column
          >yarn
          <el-table-column prop="launch" label="投送用户">
            <template slot-scope="scope">
              <p v-for="i in scope.row.launch" :key="i">
                <span>{{
                  i == 1
                    ? "男用户"
                    : i == 2
                    ? "女用户"
                    : i == 0
                    ? "投放指定用户"
                    : "VIP用户"
                }}</span>
              </p>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="publisher" label="操作"> </el-table-column> -->
        </el-table>
        <pagination
          v-show="totalA > 0"
          :total="totalA"
          :page.sync="page"
          :limit.sync="pageSize"
          @pagination="getListA"
        />
      </div>
      <el-dialog title="编辑信息" :visible.sync="dialogFormVisibleA" top="5vh">
        <el-form :model="rulesEdit">
          <el-form-item label="标题" :rules="[{ required: true }]">
            <el-input v-model="rulesEdit.title" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="内容">
            <el-input type="textarea" v-model="rulesEdit.content"></el-input>
          </el-form-item>
          <el-form-item label="投放用户" :rules="[{ required: true }]">
            <!-- <el-radio-group
              v-model="edit_radioSex"
              @change="editCheckboxChange"
            >
              <el-radio :label="1">男用户</el-radio>
              <el-radio :label="2">女用户</el-radio>
            </el-radio-group>
            <el-radio-group v-model="edit_appointId" @change="editRadioChange">
              <el-radio
                style="margin-left: 20px"
                label="指定用户投放"
              ></el-radio>
            </el-radio-group>
          </el-form-item> -->
            <!-- <el-form-item
            label="指定用户id"
            :rules="[{ required: true }]"
            v-if="appointId == '指定用户投放'"
          >
            <div style="display: flex">
              <el-input
                v-model="rulesEdit.appointId"
                placeholder="多个id请用英文逗号隔开"
                style="width: 30%"
              ></el-input>
              <upload-excel-component
                :on-success="editHandleSuccess"
                :before-upload="editBeforeUpload"
              />
            </div>
          </el-form-item> -->
            <!-- <el-radio-group v-model="rulesEdit.radioSex" @change="SexChange">
              <el-radio :label="1">男用户</el-radio>
              <el-radio :label="2">女用户</el-radio>
            </el-radio-group>
            <el-radio-group
              v-model="rulesEdit.appointId"
              @change="radioChange1"
            >
              <el-radio
                style="margin-left: 20px"
                label="指定用户投放"
              ></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            label="指定用户id"
            :rules="[{ required: true }]"
            v-if="appointId1 == '指定用户投放'"
          >
            <div style="display: flex">
              <el-input
                v-model="rulesEdit.appointId1"
                placeholder="多个id请用英文逗号隔开"
                style="width: 30%"
              ></el-input>
              <upload-excel-component
                :on-success="handleSuccess1"
                :before-upload="beforeUpload1"
              />
            </div>
          </el-form-item> -->
            <el-radio-group v-model="rulesEdit.radioSex" @change="SexChange">
              <el-radio :label="1">男用户</el-radio>
              <el-radio :label="2">女用户</el-radio>
            </el-radio-group>
            <!-- <el-checkbox-group v-model="rulesEdit.user_type">
              <el-checkbox :label="1" name="">男用户</el-checkbox>
              <el-checkbox :label="2" name="">女用户</el-checkbox>
            </el-checkbox-group> -->
          </el-form-item>
          <el-form-item label="推送时间" :rules="[{ required: true }]">
            <el-radio-group v-model="pushTime">
              <el-radio label="立即发送"></el-radio>
              <el-radio label="定时发送"></el-radio>
            </el-radio-group>

            <el-date-picker
              v-if="pushTime == '定时发送'"
              v-model="rulesEdit.pushTime"
              type="datetime"
              value-format="timestamp"
              placeholder="选择日期时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="添加图片">
            <el-upload
              class="avatar-uploader"
              :http-request="upLoadB"
              :on-preview="handlePictureCardPreviewB"
              :on-success="handleAvatarSuccessB"
              :show-file-list="false"
              action
            >
              <img
                v-if="rulesEdit.dialogImageUrl"
                :src="rulesEdit.dialogImageUrl"
                class="avatar"
                style="width: 200px; height: 180px"
              />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="添加链接">
            <el-input placeholder="请输入网址" v-model="rulesEdit.url">
              <template slot="prepend">网址</template>
            </el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisibleA = false">取 消</el-button>
          <el-button type="primary" @click="noticeAddBtnA">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="系统消息发布"
        :visible.sync="dialogFormVisible"
        top="5vh"
      >
        <el-form :model="form">
          <el-form-item label="标题" :rules="[{ required: true }]">
            <el-input v-model="form.title" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="内容" :rules="[{ required: true }]">
            <el-input type="textarea" v-model="form.content"></el-input>
          </el-form-item>
          <el-form-item
            style="display: flex"
            label="投放用户"
            :rules="[{ required: true }]"
          >
            <!-- <el-checkbox-group
              v-model="form.user_type"
              @change="checkboxChange"
            > -->
            <!-- <el-checkbox label="1">男用户</el-checkbox>
              <el-checkbox label="2">女用户</el-checkbox> -->
            <!-- <el-radio v-model="radio" label="1">男用户</el-radio>
              <el-radio v-model="radio" label="2">女用户</el-radio>
            </el-checkbox-group> -->
            <el-radio-group v-model="radioSex" @change="checkboxChange">
              <el-radio :label="1">男用户</el-radio>
              <el-radio :label="2">女用户</el-radio>
              <el-radio style="margin-left: 20px" label="0"
                >投放指定用户</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item
            label="指定用户id"
            :rules="[{ required: true }]"
            v-if="radioSex == 0"
          >
            <div style="display: flex">
              <el-input
                v-model="form.appointId"
                placeholder="多个id请用英文逗号隔开"
                style="width: 30%"
              ></el-input>
              <upload-excel-component
                :on-success="handleSuccess"
                :before-upload="beforeUpload"
              />
            </div>
          </el-form-item>
          <el-form-item label="推送时间" :rules="[{ required: true }]">
            <el-radio-group v-model="pushTime">
              <el-radio label="立即发送"></el-radio>
              <el-radio label="定时发送"></el-radio>
            </el-radio-group>

            <el-date-picker
              v-if="pushTime == '定时发送'"
              v-model="form.pushTime"
              type="datetime"
              value-format="timestamp"
              placeholder="选择日期时间"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="添加图片">
            <el-upload
              class="avatar-uploader"
              :http-request="upLoad"
              :on-preview="handlePictureCardPreview"
              :on-success="handleAvatarSuccess"
              :show-file-list="false"
              action
            >
              <img
                v-if="dialogImageUrl"
                :src="dialogImageUrl"
                class="avatar"
                style="width: 200px; height: 180px"
              />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="添加链接">
            <el-input placeholder="请输入网址" v-model="form.url">
              <template slot="prepend">网址</template>
            </el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="closeDialogFormVisible">取 消</el-button>
          <el-button type="primary" @click="noticeAddBtn">确 定</el-button>
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import {
  noticeList,
  noticeDel,
  ossToken,
  noticeAdd,
  noticeEdit,
  noticePush,
} from "@/api/NotificationManagement";
import Pagination from "@/components/Pagination"; // 分页
import { client } from "@/utils/oss.js";
import UploadExcelComponent from "@/components/UploadExcel/index.vue";

export default {
  components: { Pagination, UploadExcelComponent },
  inject: ["reload"],
  data() {
    return {
      loading: true,
      loadingA: true,
      radioSex: 1,
      edit_radioSex: "",
      appointIdArr: [],
      edit_appointIdArr: [],
      appointId: "",
      edit_appointId: "",
      index: 0,
      id: "",
      content: "",
      tableData: [],
      tableDataA: [],
      dialogFormVisibleA: false,
      dialogFormVisible: false,
      form: {
        title: "",
        content: "",
        user_type: ["1", "2", "3"],
        pushTime: "",
        imageUrl: "",
        url: "",
        appointId: "",
      },
      // 编辑弹框
      rulesEdit: {
        appointId: "",
        title: "",
        content: "",
        user_type: "",
        pushTime: "",
        dialogImageUrl: "",
        url: "",
        imageUrl: "",
        id: "",
        radioSex: "",
      },
      pushTime: "",
      total: 0,
      page: 1, //页码
      pageSize: 10, //每页条数
      totalA: 0,
      pageA: 1, //页码
      pageSizeA: 10, //每页条数
      dialogImageUrl: "",

      pickerOptions: {
        selectableRange: (() => {
          let data = new Date();
          let hour = data.getHours();
          let minute = data.getMinutes();
          let second = data.getSeconds();
          return [`${hour}:${minute}:${second} - 23:59:59`];
        })(),
        disabledDate(time) {
          var date = new Date();
          date.setFullYear(date.getFullYear() + 2);
          date.setDate(date.getDate() - 1);
          return (
            time.getTime() < Date.now() - 8.64e7 ||
            time.getTime() > date.getTime()
          );
        },
      },

      callStatisticsPickerOptions: {
        disabledDate(platformValue) {
          return platformValue.getTime() > Date.now() - 8.64e6;
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      messageTimeValStartDate: "",
      messageTimeValEndDate: "",
      messageTimeVal: "",
    };
  },

  methods: {
    // editCheckboxChange(e) {
    //   if (e != "") {
    //     // this.form.user_type = [];
    //     this.edit_appointId = "";
    //   }
    // },
    checkboxChange(e) {
      // console.log(e);

      // console.log(this.radioSex);
      if (e != "") {
        // this.form.user_type = [];
        this.appointId = "";
      }
    },
    // editRadioChange(e) {
    //   if (e == "指定用户投放") {
    //     this.edit_radioSex = "";
    //   }
    // },
    // 指定用户change事件
    radioChange(e) {
      // console.log(e);
      if (e == "指定用户投放") {
        this.radioSex = "";
      }
    },
    // 导入
    handleSuccess({ results, header }) {
      // console.log(results);
      // this.tableData = results;
      // this.tableHeader = header;

      results.forEach((item) => {
        for (let key in item) {
          this.appointIdArr.push(item[key]);
        }
        // arr.push(item.item[key]);
        // console.log(arr);
      });
      // console.log(this.appointIdArr);
      // console.log(arr);
      // let a = "12345,15487,56877,1546";
      // let b = a.split(/[,， ]/);
    },
    // editHandleSuccess(results, header) {
    //   results.forEach((item) => {
    //     for (let key in item) {
    //       this.edit_appointIdArr.push(item[key]);
    //     }
    //   });
    // },
    //列表
    noticeList() {
      this.loading = true;
      noticeList({
        page: this.page,
        pageSize: this.pageSize,
        status: "0",
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = res.data.count;
          this.loading = false;
        }
      });
    },
    // 未发送
    activeStatusA() {
      this.index = 0;
      this.page = 1;
      this.loading = true;

      noticeList({
        page: this.page,
        pageSize: this.pageSize,
        status: this.index,
        id: this.id,
        content: this.content,
        startTime: this.messageTimeValStartDate, //1.3新增
        endTime: this.messageTimeValEndDate, //1.3新增
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = res.data.count;
          this.loading = false;
        }
      });
    },
    // 已发送
    activeStatusB() {
      this.index = 1;
      this.page = 1;
      this.loadingA = true;

      noticeList({
        // page: this.pageA,
        // pageSize: this.pageSizeA,
        // status: this.index,
        id: this.id,
        content: this.content,
        page: this.page,
        pageSize: this.pageSizeA,
        status: this.index,
        startTime: this.messageTimeValStartDate, //1.3新增
        endTime: this.messageTimeValEndDate, //1.3新增
      }).then((res) => {
        if (res.code == 0) {
          this.tableDataA = res.data.list;
          this.totalA = res.data.count;
          this.loadingA = false;
        }
      });
    },
    //分页
    getList() {
      this.loading = true;

      noticeList({
        // page: this.page,
        // pageSize: this.pageSize,
        // status: this.index,
        id: this.id,
        content: this.content,
        page: this.page,
        pageSize: this.pageSize,
        status: this.index,
        startTime: this.messageTimeValStartDate, //1.3新增
        endTime: this.messageTimeValEndDate, //1.3新增
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = res.data.count;
          this.loading = false;
        }
      });
    },
    getListA() {
      this.loadingA = true;

      noticeList({
        // page: this.pageA,
        // pageSize: this.pageSizeA,
        // status: this.index,
        id: this.id,
        content: this.content,
        page: this.pageA,
        pageSize: this.pageSizeA,
        status: this.index,
        startTime: this.messageTimeValStartDate, //1.3新增
        endTime: this.messageTimeValEndDate, //1.3新增
      }).then((res) => {
        if (res.code == 0) {
          this.tableDataA = res.data.list;
          this.totalA = res.data.count;
          this.loadingA = false;
        }
      });
    },
    // 编辑信息
    editBtn(row) {
      // console.log(row);
      this.dialogFormVisibleA = true;
      this.rulesEdit.title = row.title;
      this.rulesEdit.content = row.content;
      this.rulesEdit.user_type = row.launch;
      this.rulesEdit.pushTime = row.creationTime;
      this.rulesEdit.dialogImageUrl = row.img;
      this.rulesEdit.url = row.url;
      this.rulesEdit.id = row.id;
    },
    handleSuccess1() {},
    beforeUpload1() {},
    // 查找搜索
    noticeListBtn() {
      this.page = 1;
      console.log(this.index);
      // noticeList({
      //   id: this.id,
      //   content: this.content,
      //   page: this.page,
      //   pageSize: this.pageSize,
      //   status: this.index,
      //   startTime: this.messageTimeValStartDate, //1.3新增
      //   endTime: this.messageTimeValEndDate, //1.3新增
      // }).then((res) => {
      //   if (res.code == 0) {
      //     this.tableDataA = res.data.list;
      //     this.totalA = res.data.count;
      //   }
      // });
      if (this.index == 0) {
        this.activeStatusA();
      } else {
        this.activeStatusB();
      }
    },
    //编辑弹框确认
    noticeAddBtnA() {
      if (
        this.rulesEdit.title &&
        this.rulesEdit.content &&
        this.rulesEdit.radioSex !== ""
      ) {
        noticeEdit({
          id: this.rulesEdit.id,
          title: this.rulesEdit.title, //标题
          content: this.rulesEdit.content, //内容
          user_type: [this.rulesEdit.radioSex], //投放 1.男用户 2.女用户
          pushTime: this.rulesEdit.pushTime, //推送时间
          img: this.rulesEdit.imageUrl, //添加图片
          url: this.rulesEdit.url, //添加链接
          launch_type: this.rulesEdit.radioSex,
        }).then((res) => {
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "编辑成功",
            });
            this.reload();
          }
        });
      } else {
        this.$message({
          type: "warning",
          message: "请完善必填信息",
        });
      }
    },
    //撤回
    withdrawBtn(row) {
      this.$confirm("此操作将撤回该系统消息, 是否继续?", "撤回提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          noticeDel({
            id: row.id,
          }).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: "撤回成功",
              });
              this.reload();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消撤回",
          });
        });
    },
    addPush() {
      this.dialogFormVisible = true;
      this.form.pushTime = "";
    },
    //添加系统消息
    noticeAddBtn() {
      if (this.form.title && this.form.content && this.radioSex !== "") {
        if (this.radioSex == 0) {
          if (this.appointIdArr.length >= 1 || this.form.appointId != "") {
            let arr = [];
            if (this.form.appointId != "") {
              arr = this.form.appointId.split(/[,， ]/);
            }

            this.appointIdArr = [...arr, ...this.appointIdArr];
            this.appointIdArr = [...new Set(this.appointIdArr)];
            console.log(this.appointIdArr);
            noticeAdd({
              appoint_user_id: this.appointIdArr,
              title: this.form.title, //标题
              content: this.form.content, //内容
              user_type: [this.radioSex], //投放 1.男用户 2.女用户
              pushTime: this.form.pushTime, //推送时间
              launch_type: this.radioSex,
              img: this.form.imageUrl, //添加图片
              url: this.form.url, //添加链接
            }).then((res) => {
              if (res.code == 0) {
                this.$message({
                  type: "success",
                  message: "添加成功",
                });
                this.reload();
              }
            });
          } else {
            this.$message({
              type: "warning",
              message: "请输入id",
            });
          }
        } else {
          noticeAdd({
            title: this.form.title, //标题
            content: this.form.content, //内容
            user_type: [this.radioSex], //投放 1.男用户 2.女用户
            pushTime: this.form.pushTime, //推送时间
            img: this.form.imageUrl, //添加图片
            url: this.form.url, //添加链接
            launch_type: this.radioSex,
          }).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: "添加成功",
              });
              this.reload();
            }
          });
        }
      }
    },
    //立即推送
    sendNowBtn(row) {
      noticePush({
        id: row.id,
      }).then((res) => {
        if (res.code == 0) {
          this.$message({
            type: "success",
            message: "推送成功",
          });
          this.activeStatusB();
        }
      });
    },
    handleAvatarSuccess(res, file) {
      this.dialogImageUrl = URL.createObjectURL(file.raw);
    },
    //覆盖默认的上传行为，自定义上传的实现
    async upLoad(file) {
      await ossToken({
        type: 0,
      }).then((res) => {
        if (res.code == 0) {
          this.dataObj = {
            accessKeyId: res.data.accessKey,
            accessKeySecret: res.data.accessSecret,
            securityToken: res.data.token,
            region: "oss-" + res.data.regionId,
            bucket: res.data.bucket,
          };
        }
      });
      const self = this;

      // try {
      //   // console.log(file);
      //   let fileNames =
      //     "/img/" +
      //     Math.round(new Date() / 1000) +
      //     "." +
      //     file.file.name.substring(file.file.name.lastIndexOf(".") + 1);
      //   // let fileNames = "/img/" + file.file.name;
      //   this.form.imageUrl = fileNames;
      //   //fileNames上传文件的名称
      //   //file.file上传文件的内容
      //   let cli = client(this.dataObj);
      //   let result = cli.multipartUpload(fileNames, file);
      //   self.$message({
      //     message: "上传成功",
      //     type: "success",
      //   });
      // } catch (e) {
      //   self.$message.error("上传失败");
      // }

      let files = file.file,
        point = files.name.lastIndexOf("."),
        suffix = files.name.substr(point),
        fileName = files.name.substr(0, point),
        date = Date.parse(new Date()),
        // fileNames = "/img/" + file.file.name;
        fileNames =
          "/img/" +
          Math.round(new Date() / 1000) +
          "." +
          file.file.name.substring(file.file.name.lastIndexOf(".") + 1);
      // console.log(file.file.name.substring(file.file.name.lastIndexOf(".")+1));
      this.form.imageUrl = fileNames;
      //fileNames上传文件的名称
      //file.file上传文件的内容
      client(this.dataObj)
        .multipartUpload(fileNames, file.file)
        .then((result) => {
          //下面是如果对返回结果再进行处理，根据项目需要
          self.$message({
            message: "上传成功",
            type: "success",
          });
        })
        .catch((err) => {
          self.$message.error("上传失败");
        });
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
    },
    //添加弹框取消
    closeDialogFormVisible() {
      this.dialogFormVisible = false;
      this.form.title = ""; //标题
      this.form.content = ""; //内容
      this.form.user_type = ""; //投放 1.男用户 2.女用户
      this.form.pushTime = ""; //推送时间
      this.pushTime = ""; //推送时间
      this.form.imageUrl = ""; //添加图片
      this.form.url = ""; //添加链接
    },

    focusA(time) {
      if (!this.messageTimeVal) {
        this.messageTimeVal = [];
      }
      this.messageTimeValStartDate = this.messageTimeVal[0];
      this.messageTimeValEndDate = this.messageTimeVal[1];
    },

    handleAvatarSuccessB(res, file) {
      this.rulesEdit.dialogImageUrl = URL.createObjectURL(file.raw);
    },
    //覆盖默认的上传行为，自定义上传的实现
    async upLoadB(file) {
      await ossToken({
        type: 0,
      }).then((res) => {
        if (res.code == 0) {
          this.dataObj = {
            accessKeyId: res.data.accessKey,
            accessKeySecret: res.data.accessSecret,
            securityToken: res.data.token,
            region: "oss-" + res.data.regionId,
            bucket: res.data.bucket,
          };
        }
      });
      const self = this;

      // try {
      //   let fileNames =
      //     "/img/" +
      //     Math.round(new Date() / 1000) +
      //     "." +
      //     file.file.name.substring(file.file.name.lastIndexOf(".") + 1);
      //   this.rulesEdit.imageUrl = fileNames;
      //   //fileNames上传文件的名称
      //   //file.file上传文件的内容
      //   console.log(this.dataObj);
      //   let cli = client(this.dataObj);
      //   let result = cli.multipartUpload(fileNames, file);
      //   self.$message({
      //     message: "上传成功",
      //     type: "success",
      //   });
      // } catch (e) {
      //   self.$message.error("上传失败");
      // }

      let files = file.file,
        point = files.name.lastIndexOf("."),
        suffix = files.name.substr(point),
        fileName = files.name.substr(0, point),
        date = Date.parse(new Date()),
        // fileNames = "/img/" + file.file.name;
        fileNames =
          "/img/" +
          Math.round(new Date() / 1000) +
          "." +
          file.file.name.substring(file.file.name.lastIndexOf(".") + 1);
      // console.log(file.file.name.substring(file.file.name.lastIndexOf(".")+1));
      this.rulesEdit.imageUrl = fileNames;
      //fileNames上传文件的名称
      //file.file上传文件的内容
      client(this.dataObj)
        .multipartUpload(fileNames, file.file)
        .then((result) => {
          //下面是如果对返回结果再进行处理，根据项目需要
          self.$message({
            message: "上传成功",
            type: "success",
          });
        })
        .catch((err) => {
          self.$message.error("上传失败");
        });
    },
    handlePictureCardPreviewB(file) {
      this.rulesEdit.dialogImageUrl = file.url;
    },
  },
  created() {
    this.noticeList();
  },
};
</script>

<style lang="less" >
.notificationManagementList {
  margin: 30px;
  height: 100%;
  .noticeListBox {
    display: flex;
    justify-content: flex-start;
  }
  .p {
    display: flex;
    p {
      width: 100px;
      height: 40px;
      line-height: 40px;
      text-align: center;
    }
  }
  .active {
    background-color: #0079fe;
    color: #fff;
    border-radius: 10px;
  }
  .el-table {
    margin-top: 20px;
  }
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    margin-left: 20px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  .img {
    width: 100px;
    height: 100px;
    border-radius: 4px;
  }
}
</style>